<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Http;
use Carbon\Carbon;


class OaLinkageController extends Controller
{

    public function misdeed(Request $request)
    {

        $data = $request->json()->all();
        $id_card= $data['id_card'];
        $notes= $data['notes'];
        $misdeed = $data['misdeed'];

        if($misdeed < 1 || $misdeed > 3){
            return $this->ErrJson("行为编码错误");
        }

        $is_exist = DB::table('work_user')->where('id_card',$id_card)->first();
        if(empty($is_exist)){
            return $this->ErrJson("身份证号错误或人员不存在");
        }


        DB::table('work_user')->where('id_card',$id_card)->update(['notes'=>$notes,'misdeed'=>$misdeed]);

        $history = [];
        $history['name'] = $is_exist->name;
        $history['id_card'] = $is_exist->id_card;
        $history['engineering'] = $is_exist->engineering;
        $history['type'] = 4;
        $history['details'] = '劣迹';
        $history['enter_time'] = $is_exist->enter_time;
        $history['created_at'] = Carbon::now();
        DB::table('work_user_history')->insert($history);


        return $this->OkJson("不端行为记录成功");
    }


}
